/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package de.editura.oxygen.severin.imageviewer.features.io.resources;

import de.editura.oxygen.severin.imageviewer.features.knownDatamodels.KnownDatamodels;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

/**
 *
 * @author kschmidtner
 */
public class KnownDatamodelMarshaller {

    public static void marshallKnownDatamodels (KnownDatamodels kdms, File kdmXmlFile) {
        JAXBContext ctx = null;
        FileWriter fw = null;
        try {
            ctx = JAXBContext.newInstance(KnownDatamodels.class);
            Marshaller m = ctx.createMarshaller();
            m.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE ); 
            fw = new FileWriter(kdmXmlFile);
            m.marshal(kdms, fw);

        } catch (JAXBException ex) {
            Logger.getLogger(KnownDatamodelMarshaller.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(KnownDatamodelMarshaller.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                fw.close();
            } catch (IOException ex) {
                Logger.getLogger(KnownDatamodelMarshaller.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

    }

}
